<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例3</title>
    <link rel="stylesheet" href="../css/index.css">
    <style>
        h1 {
            color: red;
        }
    </style>
</head>

<body>
    <div class="content" style="width:200px;">
        <input type="text" id="array">
        <button onclick="sum()">求和</button>
        <h1 class="sum"></h1>
    </div>

    <script>
        let h = document.querySelector('.sum')

        function sum() {
            let sum = 0
            let s = document.querySelector('#array').value
            let arry = s.split(',')
            arry.map(r => sum += Number(r))
            h.innerText = sum
        }
    </script>
</body>

</html>